﻿using System.Text.Json.Serialization;
using System.Text.Json;

namespace HPSocketLibrary
{


    /// <summary>
    /// 自定义json的IntPtr类型序列化
    /// </summary>
    public class IntPtrConverterUsingIntParse : JsonConverter<IntPtr>
    {
        public override IntPtr Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return (IntPtr)reader.GetInt64();
        }

        public override void Write(Utf8JsonWriter writer, IntPtr value, JsonSerializerOptions options)
        {
            writer.WriteNumberValue(value.ToInt64());
        }
    }
}